package com.duanjw.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AopApplication {
	public static void main(String[] args) {
		ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("spring.xml");
		classPathXmlApplicationContext.refresh();
		UserService userService = (UserService)classPathXmlApplicationContext.getBean("userService");
		userService.show();
	}
}

@Aspect
class AspectConfig {
	@Pointcut("execution(* com.duanjw.aop..*(..))")
	public void pointCut(){}
	@Before("pointCut()")
	public void before(){
		System.out.println("before");
	}
	@After("pointCut()")
	public void after(){
		System.out.println("after");
	}
	@Around("pointCut()")
	public void around(ProceedingJoinPoint joinPoint) throws Throwable{
		System.out.println("around - before");
		joinPoint.proceed();
		System.out.println("around - after");
	}

}
class User{
	private int id;
	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}
class UserService {
	public void show(){
		System.out.println("UserService.show()");
	}
}
